/****** Object:  Stored Procedure [dbo].spNhomHangInsert Script Date: 6/11/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[spNhomHangInsert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE [dbo].[spNhomHangInsert]
GO

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		12/06/2012	SongTM					Innit created
*******************************************************************************/

CREATE PROCEDURE [dbo].[spNhomHangInsert]
(
	@MaNH nvarchar(4) output,
	@TenNH nvarchar(30),
	@GhiChu nvarchar(50)
)
WITH ENCRYPTION

AS

SET NOCOUNT ON
if not exists (select * from [tbl_NhomHang])
	Set @MaNH=1
else
	Set @MaNH=(select RIGHT(MAX([MaNH]),2) from [tbl_NhomHang])+1
Set @MaNH='NH'+REPLICATE('0',2-LEN(@MaNH))+@MaNH  
INSERT INTO [tbl_NhomHang]
(
	[MaNH],
	[TenNH],
	[GhiChu]
)
VALUES
(
	@MaNH,
	@TenNH,
	@GhiChu
)
GO

--GRANT EXECUTE ON [dbo].[spNhomHangInsert] TO [sa]
--GO
